import axios from 'axios';

const service = axios.create({
  baseURL: import.meta.env.VITE_APP_BASE_URL,
  timeout: 15000
});

service.interceptors.request.use(config => {
  config.headers['X-Access-Token'] = localStorage.getItem('token');
  return config;
}, error => {
  return Promise.reject(error);
})

service.interceptors.response.use(response => {
  if (response.status === 200 && response.data.code === 200) {
    return Promise.resolve(response.data);
  } else {
    return Promise.resolve(response.data);
  }
}, error => {
  return Promise.reject(error);
})

export default service;
